/**
  * Author: Mei
  * Date: 2021-01-13 10:21
  * Description: chrono库
  * chrono库主要包含三种类型：时间间隔duration、时钟clocks和时间点time point
  *
  */
#include <iostream>
#include <chrono>
#include <ctime>
#include <thread>
#include <iomanip>

using namespace std::chrono;
using namespace std;
int main() {
    //1、获取系统时间的clocks
    system_clock::time_point t1 = system_clock::now();
    cout << "Hello World!" << endl;
    this_thread::sleep_for(chrono::seconds(1));
    system_clock::time_point t2 = system_clock::now();

    cout << (t2-t1).count() << endl; //重载运算符-  返回duration

    cout << duration_cast<microseconds>(t2-t1).count() << endl;

    //time_t now_c = system_clock::to_time_t(time_point);  //将time_point转为time_t
    //time_point tp = system_clock::from_time_t(now_c); //将time_t转为tim_point

    //steady_clock可以获取稳定可靠的时间间隔，后一次调用now()的值和前一次的差值不会
    //    因为修改了系统时间而改变，从而保证了稳定的时间间隔

    time_t now_t = system_clock::to_time_t(system_clock::now());
    cout << put_time(localtime(&now_t), "%Y-%M-%d %H-%M-%S") << endl;

    return 0;
}